/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package motiveai.factors;

/**
 *
 * @author oxplay
 */
public class FactorInteger extends AbstractFactor {

    private int valueNeeded = 0;
    private int scaleEpsilon = 0;
    private int valueDefault = 0;

    public FactorInteger(int valueDefault, int valueNeeded, int scaleEpsilon, int performance) {
        super(performance);
        this.valueDefault = valueDefault;
        this.valueNeeded = valueNeeded;
        this.scaleEpsilon = scaleEpsilon;
    }

    public int getScaleEpsilon() {
        return scaleEpsilon;
    }

    public void setScaleEpsilon(short maxEpsilon) {
        this.scaleEpsilon = maxEpsilon;
    }

    public int getDefaultValue() {
        return valueDefault;
    }

    public void setDefaultValue(int value) {
        this.valueDefault = value;
    }

    public int getValueNeeded() {
        return valueNeeded;
    }

    public void setValueNeeded(int valueNeeded) {
        this.valueNeeded = valueNeeded;
    }

    public float getScaledPerformance(int value) {
        int valueDistance = Math.abs(this.valueNeeded - value);
        if (valueDistance == 0) {
            return (float) getPerformance();
        } else if (valueDistance <= scaleEpsilon) {
            return (float) getPerformance() * (float) valueDistance / (float) scaleEpsilon;
        }
        return 0;
    }
}
